package com.mutable.app.controller;

import com.mutable.app.entity.User;
import com.mutable.app.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("")
public class UserController {

    @Autowired
    private UserService userService;

    @GetMapping("/save/{name}")
    public String saveUser(@PathVariable(name = "name") String name) {

        User user = new User();
        user.setName(name);
        userService.saveUser(user);

        return "Success!";
    }

    @GetMapping("/update/{id}/{newname}")
    public String updateUser(@PathVariable("id")Integer id, @PathVariable("newname")String name) {
        User user = new User();
        user.setName(name);
        user.setId(id);
        userService.updateUser(user);
        return "Update Success!";
    }
}
